#include "bullet.h"
#include <qmath.h>

Bullet::Bullet(): x(0.0), y(0.0), z(0.0), dx(0.0), dz(0.0)
{
}

void Bullet::setPosition(double px, double py, double pz)
{
    x = px;
    y = py;
    z = pz;
}

void Bullet::SetDirection(double x, double z)
{
    dx = x;
    dz = z;
}

void Bullet::Advance()
{
    x += dx;
    z += dz;
}

int Bullet::cell(int rows, int columns) const
{
    int r = qFloor(z);
    int c = qFloor(x);
    bool betweenR = 0 <= r && r < rows;
    bool betweenC = 0 <= c && c < columns;
    if(betweenR && betweenC) return r * columns + c;
    else return -1;
}

double Bullet::px() const
{
    return x;
}

double Bullet::py() const
{
    return y;
}

double Bullet::pz() const
{
    return z;
}
